package com.ftg.learn.amqp.routing;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author 布衣
 */
public class Cerror {

    public static void main(String[] args) throws IOException, TimeoutException {
        //基础信息
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("10.2.40.82");
        factory.setPort(5672);
        factory.setUsername("admin");
        factory.setPassword("admin");
        factory.setVirtualHost("/demo");


        //拿到连接
        Connection connection = factory.newConnection();
        //创建channel
        Channel channel = connection.createChannel();

        String queueName = channel.queueDeclare().getQueue();
        channel.exchangeDeclare("advice", BuiltinExchangeType.DIRECT);
        channel.queueBind(queueName, "advice", "error");

        channel.basicConsume(queueName, true, (consumerTag, message) -> System.out.println("接收到消息：" + new String(message.getBody())), consumerTag -> {
        });
    }

}
